package com.xing.Login.Action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.xing.Login.Service.LoginService;
import com.xing.User.Entity.User;

/**
*@author xingxing
*@version 
*@time 2017年10月19日 下午9:58:19 
*class explain：
*/
@Controller
@Scope("prototype")
public class LoginAction extends ActionSupport {
	private HttpServletResponse response = ServletActionContext.getResponse();//为了得到response,响应
	private HttpServletRequest request = ServletActionContext.getRequest();//为了得到request,请求

	@Autowired
	LoginService loginService;
	
	/**
	 * @author xingxing
	 * @date 2017-10-19 22:11:41
	 * @return 成功失败
	 * 跳转主界面
	 */
	public String login() {
		//获取HttpSession 通过request获取的
		HttpSession session =request.getSession();	
		//查询是否存在这个User
		List<User> list=(List<User>)loginService.objectfind(user);
		//判断是否存在
		if(list.size()>0) {
			//通过上边的查询拿到了User，把User放进Session中，这里自定义了一个参数名字叫做user
			session.setAttribute("user", (User)list.get(0));
			return SUCCESS;
		}
		return ERROR;
	}
			
	//Struts2特性。省略servlet的内容
	private User user;
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
}
